package iddscui;

import Main.Parameters;
import java.io.File;
import java.io.FilenameFilter;

/**
 *
 * @author ZeM
 */
public class FileTask {

    /**
     * Check if file exists
     * @param path - path to file
     * @return true if exist
     */
    public boolean Exist(String path) {
        File file = new File(path);
        if (file.exists()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Delete file
     * @param path - path to file
     * @return true if succesfully deleted
     */
    public boolean Delete(String path) {
        File file = new File(path);
        if (file.delete()) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Getting List of task files in folder with tasks
     * @return String[] of found tasks
     */
    public String[] List() {
        File f1 = new File(Parameters.TaskFolder);
        String[] ls;
        FilenameFilter filter = new TaskFilter();
        return ls = f1.list(filter);

    }
}

/**
 * Filter for Task Files
 * @author ZeM
 */
class TaskFilter implements FilenameFilter { //filter

    public boolean accept(File dir, String name) {
        return (name.endsWith(Parameters.FileTaskExtension));
    }
}

